import { mathType } from "./face";

// 意图配置接口
export interface IntentConfig {
    command: string;
    action: string;
    mathType: mathType;
    component?: any;
    isHideMath?: boolean;
}

// 按钮配置接口
export interface ButtonConfig {
    text: string;
    action: string;
    mathType: mathType;
    isHideMath?: boolean;
}

// 场景意图配置接口
export interface SceneIntentConfig {
    command: string;
    action: string;
    mathType: mathType;
    isHideMath: boolean;
}

// 意图注册工具类
export class IntentHelper {
    /**
     * 批量注册意图
     * @param configs 意图配置数组
     * @param registerFunc 注册函数
     * @param self 组件实例
     */
    static registerIntents(
        configs: IntentConfig[], 
        registerFunc: (mathType: mathType, command: string, action: Function, self: any, isHideMath?: boolean) => void,
        self: any
    ): void {
        configs.forEach(config => {
            const targetComponent = config.component || self;
            registerFunc(
                config.mathType,
                config.command,
                targetComponent[config.action],
                targetComponent,
                config.isHideMath
            );
        });
    }

    /**
     * 批量注册按钮意图
     * @param configs 按钮配置数组
     * @param registerFunc 注册函数
     * @param self 组件实例
     * @param card 卡片对象
     */
    static registerButtonIntents(
        configs: ButtonConfig[],
        registerFunc: (mathType: mathType, command: string, action: Function, self: any, isHideMath?: boolean) => void,
        self: any,
        card: any
    ): void {
        configs.forEach(config => {
            card.button(config.text, () => {
                registerFunc(
                    config.mathType,
                    config.text,
                    (self as any)[config.action],
                    self,
                    config.isHideMath
                );
            });
        });
    }

    /**
     * 批量注册场景意图
     * @param configs 场景意图配置数组
     * @param registerFunc 注册函数
     * @param self 场景实例
     */
    static registerSceneIntents(
        configs: SceneIntentConfig[],
        registerFunc: (mathType: mathType, command: string, isHideMath: boolean, action: Function, self?: any) => void,
        self: any
    ): void {
        configs.forEach(config => {
            registerFunc(
                config.mathType,
                config.command,
                config.isHideMath,
                (self as any)[config.action],
                self
            );
        });
    }
} 